<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>商品二级菜单（移入）</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    ul {
      list-style: none;
    }

    .shop {
      width: 700px;
      height: 500px;
      background: orange;
      margin: 0 auto;
      margin-top: 200px;
    }

    .main {
      position: relative;
    }

    ul {
      float: left;
      width: 150px;
      height: 500px;
    }

    .item {
      position: relative;
      width: 150px;
      height: 50px;
      background: #eee;
      text-align: center;
      padding-top: 13px;
      border: 1px solid orange;
      cursor: pointer;
    }

    .activate {
      border-right: none;
    }

    .content {
      position: absolute;
      top: 0;
      left: 150px;
      width: 550px;
      height: 500px;
      background: #eee;
      border: 1px solid orange;
      font-size: 30px;
      text-align: center;
      padding-top: 50px;
      display: none;
    }

    .on {
      display: block;
      border-left: none;
    }

    .default {
      position: absolute;
      top: 0;
      left: 150px;
      width: 550px;
      height: 500px;
      background: #eee;
      border: 1px solid orange;
      font-size: 30px;
      text-align: center;
      padding-top: 50px;
    }
  </style>
</head>

<body>
  <div class="shop">
    <div class="main">
      <ul class="fl">

        <li>
          <div class="item ">商品1</div>
          <div class="content">内容1</div>
        </li>
        <li>
          <div class="item">商品2</div>
          <div class="content">内容2</div>
        </li>
        <li>
          <div class="item">商品3</div>
          <div class="content">内容3</div>
        </li>
        <li>
          <div class="item">商品4</div>
          <div class="content">内容4</div>
        </li>
      </ul>
      <div class="default">默认页面</div>
    </div>
  </div>
  <script>
    // 获取所有的菜单和内容
    let shops = document.querySelectorAll(".item")
    let contents = document.querySelectorAll(".content")
    let def = document.querySelector(".default")

    // 注册移入事件 移入显示对应内容
    shops.forEach(function (shop, index) {
      shop.addEventListener("mouseenter", function () {
        def.style.display = "none"
        this.classList.add("activate")
        contents[index].classList.add("on")
      })
      shop.addEventListener("mouseleave", function () {
        this.classList.remove("activate")
        contents[index].classList.remove("on")
        def.style.display = "block"
      })
    })
  </script>
</body>

</html>